#include "debug.h"
#include "../DDIC/AllDDIC.h"
#include "usbd_cdc.h"


//25个绑点，高低位共50位
u8 VTDR_bufferR[50];
u8 VTDR_bufferG[50];
u8 VTDR_bufferB[50];

void VTDR7120_Write_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFfd);
    SSD2828_W_Array(SigMode,channel,buffer,2);                               
    delay_ms(5);
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    buffer[4] = Uart_Error_None;
    buffer[5] = 0;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写寄存器状态  ：ok  
}
void VTDR7120_Read_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u16 tmp;
    buffer[1]=0x03;
    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);                               
    SSD2828_W_Reg(SigMode,channel,0xC1,buffer[2]); //return package size                                
    SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
    buffer[0] = 0x01;
    buffer[1] = buffer[3];                        
    SSD2828_W_Array(SigMode,channel,buffer,0);
    delay_ms(5);  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
    SSD2828_W_Cmd(SigMode,channel,0xFF);
    for(i=0;i<buffer[2]-1;i++)
    {
        SSD2828_W_Cmd(SigMode,channel,0xFA);		
        tmp=SPI3_Read_u16_Data(channel);
        buffer[4+i]=tmp>>8;
        buffer[5+i]=tmp;
        delay_ms(5);
        i++;
    }
		buffer[0]=0x60;	
		buffer[1]=0x02; 
	SSD2828_W_Reg(SigMode,channel,0xB7,0x034b);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 读取的 寄存器数据  ：ok 
}




void VTDR7120_Write_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[7];
    u8 i,j,k=0,temp;
	u8 m = 0x00;
					
		if((buffer[3]&0xFF)==0x00)
		{
			for( i = 0;i<16;i++)   //8个绑点                                                                                  
			{VTDR_bufferR[i]=buffer[i+5];}	    
			for( i = 0;i<16;i++)   //8个绑点                                                                                 
			{VTDR_bufferR[i+16]=buffer[i+21];}
			for( i = 0;i<16;i++)   //8个绑点	                                                                                  
			{VTDR_bufferR[i+32]=buffer[i+37];}
			for( i = 0;i<2;i++)   //1个绑点	                                                                                  
			{VTDR_bufferR[i+48]=buffer[i+53];}
	     }	
		else if((buffer[3]&0xFF)==0x42)
		{
			for( i = 0;i<16;i++)   //8个绑点
			{VTDR_bufferG[i]=buffer[i+5];} 	 //高位在前，低位在后；如07ff  VTDR_bufferG[i]=07 VTDR_bufferG[i+1]=ff
			for( i = 0;i<16;i++)   //8个绑点
			{VTDR_bufferG[i+16]=buffer[i+21];} 		 
			for( i = 0;i<16;i++)   //8个绑点
			{VTDR_bufferG[i+32]=buffer[i+37];}	 
			for( i = 0;i<2;i++)   //1个绑点
			{VTDR_bufferG[i+48]=buffer[i+53];}
		}
		else if((buffer[3]&0xFF)==0x81)
		{
			for( i = 0;i<16;i++)   //8个绑点
			{VTDR_bufferB[i]=buffer[i+5];} 		 
			for( i = 0;i<16;i++)   //8个绑点
			{VTDR_bufferB[i+16]=buffer[i+21];}		 
			for( i = 0;i<16;i++)   //8个绑点
			{VTDR_bufferB[i+32]=buffer[i+37];}		 
			for( i = 0;i<2;i++)   //1个绑点
			{VTDR_bufferB[i+48]=buffer[i+53];}
	  }
		SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
		delay_ms(2);		

		buffer1[0] = 0x03;        
        buffer1[1] = 0xF0;
        buffer1[2] = 0xAA;
	    buffer1[3] = 0x13;//page3
        SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	    buffer1[0] = 0x02;        
        buffer1[1] = 0xC4;
        buffer1[2] = 0x01;//unlock
        SSD2828_W_Array(SigMode,channel,buffer1,0);		 		                                                                              			         
		buffer1[1] = 0xBF;//Select 
		buffer1[2] = buffer[4]; //gamma_group_sel
        //buffer[4]为上位机传下来的值，即调gamma时选的值
        //gamma1=BF,01;gamma2=BF,02;gamma3=BF,03;gamma4=BF,04;………………gamma8=BF,08;
        //BE为0默认为normal下。
        SSD2828_W_Array(SigMode,channel,buffer1,0);		        
		delay_ms(5);
        //------------------------------RED---------------------------------
        SSD2828_W_Reg(SigMode,channel,0xBC,17); //设定传输数据长度为17  写
		SSD2828_W_Cmd(SigMode,channel,0xBF);//2828 的BF寄存器，可写8位 16位值，想写的值往BF中放即可
		SSD2828_W_Data(SigMode,channel,0xB0); //GAMMA RED GROUP1
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferR[i]);	
		}			
        //相当于写了B0,x1,x2,x3……x16 共17个        
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB1); //GAMMA RED GROUP2
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferR[i+16]);	
		}		
        //相当于写了B1,x1,x2,x3……x16 共17个    
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB2); //GAMMA RED GROUP3
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferR[i+32]);	
		}	
		SSD2828_W_Reg(SigMode,channel,0xBC,3); //设定传输数据长度为3
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB3); //GAMMA RED GROUP4
		for(i=0; i<2; i++)
		{     
        SSD2828_W_Data(SigMode,channel,VTDR_bufferR[i+48]);	
		}
        //------------------------------GREEN---------------------------------
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB4); //GAMMA GREEN GROUP1----第一组Green绑点
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferG[i]);	
		}		
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 			
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB5); //GAMMA GREEN GROUP2
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferG[i+16]);	
		}	
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 			
		SSD2828_W_Cmd(SigMode,channel,0xBF);
		SSD2828_W_Data(SigMode,channel,0xB6); //GAMMA GREEN GROUP3
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferG[i+32]);
		}
		SSD2828_W_Reg(SigMode,channel,0xBC,3);
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB7); //GAMMA GREEN GROUP3
		for(i=0; i<2; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferG[i+48]);
		}
        //------------------------------BULE---------------------------------		
	
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB8); //GAMMA BLUE GROUP1
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferB[i]);	
		}		
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB9); //GAMMA BLUE GROUP2
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferB[i+16]);	
		}	
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 			
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xBA); //GAMMA BLUE GROUP3
		for(i=0; i<16; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferB[i+32]);	
		}			 
		SSD2828_W_Reg(SigMode,channel,0xBC,3); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xBB); //GAMMA BLUE GROUP4
		for(i=0; i<2; i++)
		{
		SSD2828_W_Data(SigMode,channel,VTDR_bufferB[i+48]);	
		}
		delay_ms(2); 
        //----        
        buffer1[2] = 0x02;		//数据长度		
        buffer1[1] = 0xC4;
        buffer1[2] = 0x00;  // LOCK 锁定 
        SSD2828_W_Array(SigMode,channel,buffer1,0);		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);	//切回高速			
		delay_ms(2); 
        
        //下面是什么意思？
        buffer[0]=0x60;	//VTDR7120
        buffer[1]=0x08;		
        buffer[4] = Uart_Error_None;
        buffer[5] = 0;
        STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);    //返回 写寄存器状态  ：ok   
}








void VTDR7120_Read_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
        u8 buffer1[7];
        u16 tmp;
        u8 i,j;
	
        SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        delay_ms(5);	
        buffer1[0] = 0x03;        
        buffer1[1] = 0xF0;
        buffer1[2] = 0xAA;
        buffer1[3] = 0x13;
        SSD2828_W_Array(SigMode,channel,buffer1,0);		 
        buffer1[0] = 0x02;        
        buffer1[1] = 0xC4;
        buffer1[2] = 0x10;//vtdr 7120 需设为0x10; 之前为0x01
        SSD2828_W_Array(SigMode,channel,buffer1,0);		 		                                                                              			         
        buffer1[1] = 0xBF;
        buffer1[2] = buffer[4]; //gamma_group_sel
        SSD2828_W_Array(SigMode,channel,buffer1,0);		        
        buffer1[1] = 0xC4;
        buffer1[2] = 0x00; //为什么？？？   
		SSD2828_W_Array(SigMode,channel,buffer1,0);		
	    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	    SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置16个（十进制0x10）	    
	    delay_ms(2);			 
		buffer1[0] = 0x02;        
        buffer1[1] = 0xB0;          
        SSD2828_W_Array(SigMode,channel,buffer1,0);//写一个B0		 
	    delay_ms(2);  //GAMMA RED GROUP1
		SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);//SPI 读数据的寄存器
		SSD2828_W_Cmd(SigMode,channel,0xFF);//回读值必须写个命令FF
		delay_ms(2);		
		for(i=0;i<16;i++)
		  {
          SSD2828_W_Cmd(SigMode,channel,0xFA);	//SPI 读数据的寄存器	
          tmp=SPI3_Read_u16_Data(channel);
          VTDR_bufferR[i]=tmp>>8;
          VTDR_bufferR[i+1]=tmp;
          delay_ms(5);
          i++;			
		  }
		 SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置	    
	     delay_ms(2);
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB1; //读第二组绑点         
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA RED GROUP2
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);
	  for(i=0;i<16;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferR[i+16]=tmp>>8;
      VTDR_bufferR[i+17]=tmp;
      delay_ms(5);
      i++;			
      }	
      SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置	    
      delay_ms(2);		 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB2;  //读第三组绑点            
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);     //GAMMA RED GROUP3
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
      SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);	
	  for(i=0;i<16;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferR[i+32]=tmp>>8;
      VTDR_bufferR[i+33]=tmp;
      delay_ms(5);
      i++;			
      }	
      SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //返回个数设置2个	    
      delay_ms(2);
				 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB3;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);  //GAMMA RED GROUP4
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);	
      for(i=0;i<2;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferR[i+48]=tmp>>8;
      VTDR_bufferR[i+49]=tmp;
      delay_ms(5);
      i++;			
      }//回读值放到VTDR_bufferR[]里面
	  SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置	    
	  delay_ms(2);		 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB4;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA GREEN GROUP1
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
      SSD2828_W_Cmd(SigMode,channel,0xFF);
      delay_ms(2);	
	  for(i=0;i<16;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferG[i]=tmp>>8;
      VTDR_bufferG[i+1]=tmp;
      delay_ms(5);
      i++;			
      }	
      SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置	    
	  delay_ms(2);		 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB5;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA GREEN GROUP2
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
      delay_ms(2);	
      for(i=0;i<16;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferG[i+16]=tmp>>8;
      VTDR_bufferG[i+17]=tmp;
      delay_ms(5);
      i++;			
      }
			
      SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置	    
	  delay_ms(2);		 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB6;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA GREEN GROUP3
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);	
      for(i=0;i<16;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferG[i+32]=tmp>>8;
      VTDR_bufferG[i+33]=tmp;
      delay_ms(5);
      i++;			
      }
			
	  SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //返回个数设置	    
	  delay_ms(2);	 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB7;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA GREEN GROUP4
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);	
      for(i=0;i<2;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferG[i+48]=tmp>>8;
      VTDR_bufferG[i+49]=tmp;
      delay_ms(5);
      i++;			
      }
			
	  SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置	    
	  delay_ms(2);
				 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB8;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA BLUE GROUP1
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);	
	  for(i=0;i<16;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferB[i]=tmp>>8;
      VTDR_bufferB[i+1]=tmp;
      delay_ms(5);
      i++;			
      }	
	  SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置	    
	  delay_ms(2);
				 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xB9;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA BLUE GROUP2
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);	
	  for(i=0;i<16;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferB[i+16]=tmp>>8;
      VTDR_bufferB[i+17]=tmp;
      delay_ms(5);
      i++;			
      }
	  SSD2828_W_Reg(SigMode,channel,0xC1,0x0010); //返回个数设置	    
	  delay_ms(2);		 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xBA;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA BLUE GROUP3
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);	
	  for(i=0;i<16;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferB[i+32]=tmp>>8;
      VTDR_bufferB[i+33]=tmp;
      delay_ms(5);
      i++;			
      }	
	  SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //返回个数设置	    
	  delay_ms(2);
				 
	  buffer1[0] = 0x02;        
      buffer1[1] = 0xBB;          
      SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  delay_ms(2);                 //GAMMA BLUE GROUP3
	  SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	  SSD2828_W_Cmd(SigMode,channel,0xFF);
	  delay_ms(2);	
      for(i=0;i<2;i++)
      {
      SSD2828_W_Cmd(SigMode,channel,0xFA);		
      tmp=SPI3_Read_u16_Data(channel);
      VTDR_bufferB[i+48]=tmp>>8;
      VTDR_bufferB[i+49]=tmp;
      delay_ms(5);
      i++;			
      }
      //把值放到VTDR_bufferX[]的值存到buffer[]里面传到上位机
	  if((buffer[3]&0xff)==0x00)  //GAMMA RED
	  {     
			for(j=0;j<50;j++)
			{
				buffer[4+j]=VTDR_bufferR[j];	  	
			}               			   
	  }
	  else if((buffer[3]&0xff)==0x42) //GAMMA GREEN
      {	
            for(j=0;j<50;j++)
                {
                    buffer[4+j]=VTDR_bufferG[j];	  		
                }              
      }
	  else if((buffer[3]&0xff)==0x81)   //GAMMA BLUE
		{		
			for(j=0;j<50;j++)
			{
				buffer[4+j]=VTDR_bufferB[j];								
			}        
		} 
					
    buffer[0]=0x60;	//VTDR7120
    buffer[1]=0x09;
	delay_ms(15);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);          //返回 读取的 Gamma数据  ：ok  		
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
}






void VTDR7120_Gamma_OTP_Start(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
      u8 buffer1[10];
	  u8 mtp_flag;
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);// 切低速
      delay_ms(15); 
      buffer1[0] = 0x01;//下发代码长度
      buffer1[1] = 0x28;//下28命令                  
      SSD2828_W_Array(SigMode,channel,buffer1,0); 
	  delay_ms(10); 
	  buffer1[0] = 0x03;
      buffer1[1] = 0xF0; 
	  buffer1[2] = 0xAA;
	  buffer1[3] = 0x12;  //写 F0,AA,12  进CM2 P2 代码
      SSD2828_W_Array(SigMode,channel,buffer1,0); 
	  delay_ms(1); 
	  buffer1[0] = 0x02;
      buffer1[1] = 0xCA; 
	  buffer1[2] = 0x01;//CA,01 OTP Power Enable
      SSD2828_W_Array(SigMode,channel,buffer1,0); 
	  delay_ms(1); 		
	  buffer1[0] = 0x04;//四个代码长度
	  buffer1[1] = 0xE6;	
      if(buffer[3]==0x0D)  //otp Gamma--------------不明白
          {	 //gamma在page3上么？
			buffer1[2] = 0x00;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x80; 
		}
	  else if(buffer[3]==0x0E)  //otp ALL
		{
			buffer1[2] = 0xBF;  //Application Note p107
			buffer1[3] = 0x9F;
			buffer1[4] = 0x80;  //能不能包括gamma？？
		}
	  else if(buffer[3]==0x0F)  //otp PAGE 0   ----ok
		{
			buffer1[2] = 0xB1;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x00;  
		}
	  else if(buffer[3]==0x1B)  //otp PAGE 1 ---ok
		{	 
			buffer1[2] = 0x02;  
			buffer1[3] = 0x80;
			buffer1[4] = 0x00;  
		}
	  else if(buffer[3]==0x1C)  //otp PAGE 2 ---ok
		{
			buffer1[2] = 0x04;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x00;  
		}
	  else if(buffer[3]==0x1D)  //otp PAGE 5 ---ok
		{
			buffer1[2] = 0x00;  
			buffer1[3] = 0x02;
			buffer1[4] = 0x00;  
		}
      else if(buffer[3]==0x1A)  //otp PAGE 4  -----ok
		{		 
			buffer1[2] = 0x00;  
			buffer1[3] = 0x01;
			buffer1[4] = 0x00;  
		}
      else if(buffer[3]==0x1E)  //otp PAGE 7  ---ok
		{
			buffer1[2] = 0x00;  
			buffer1[3] = 0x08;
			buffer1[4] = 0x00;  
		}
      else if(buffer[3]==0x1F)  //otp PAGE 8  ---ok
		{
			buffer1[2] = 0x00;  
			buffer1[3] = 0x10;
			buffer1[4] = 0x00;  
		}	
//      else if(buffer[3]==0x20)  //otp PAGE 3  ---是gamma么？如果是则注销
//        {
//            buffer1[2] = 0x00;  
//            buffer1[3] = 0x00;
//            buffer1[4] = 0x80;  
//        }	
      else if(buffer[3]==0x21)  //otp PAGE 6  ---上位机上未写
        {
            buffer1[2] = 0x00;  
            buffer1[3] = 0x04;
            buffer1[4] = 0x00;  
        }	
        
       SSD2828_W_Array(SigMode,channel,buffer1,0); 
       delay_ms(5); 
       buffer1[0] = 0x02;
       buffer1[1] = 0xCA; 
	   buffer1[2] = 0x03;
       SSD2828_W_Array(SigMode,channel,buffer1,0); 
       delay_ms(5); 
       buffer1[0] = 0x04;//长度
       buffer1[1] = 0xE7;
       buffer1[2] = 0x88;    
       buffer1[3] = 0x55;    
       buffer1[4] = 0x11; //E7,88,55,11 OTP标志代码 
       SSD2828_W_Array(SigMode,channel,buffer1,0);	
       delay_ms(3000); 
       buffer1[0] = 0x02;
       buffer1[1] = 0xCA;
       buffer1[2] = 0x01;  //OTP Power Disable
       SSD2828_W_Array(SigMode,channel,buffer1,0);     		 
       delay_ms(10);
       buffer1[0] = 0x04;
       buffer1[1] = 0xE6;
       buffer1[2] = 0x00;  
       buffer1[3] = 0x00;
       buffer1[4] = 0x00; //E6,00,00,00 OTP Program Group Disable
       SSD2828_W_Array(SigMode,channel,buffer1,0); 
       delay_ms(10); 
       
       //buffer[1] = 0x0E;//--------------???????这边是什么意思？？？？
       buffer[2] = 0x02;
       buffer[3] = Uart_Error_None;   //返回 OTP Gamma数据  ：OK
       buffer[4] = 0;
       STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);         
}


void VTDR7120_Read_Flash_ID(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  u8 buffer1[4]; 
	  u16 tmp;
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);	
	  delay_ms(5);
	  buffer1[0] = 0x01;
      buffer1[1] = 0x28;  //x写0x28                  
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[0] = 0x03;
      buffer1[1] = 0xF0; 
	  buffer1[2] = 0xAA; 
	  buffer1[3] = 0x10; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[1] = 0xEA; 
	  buffer1[2] = 0x30; 
      buffer1[3] = 0x00; //是否为02？？？、
      SSD2828_W_Array(SigMode,channel,buffer1,0);	   
	  buffer1[0] = 0x02;
      buffer1[1] = 0xEE; 
	  buffer1[2] = 0xAB; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[1] = 0xED; 
	  buffer1[2] = 0x20; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
	  delay_ms(100);  
      buffer1[1] = 0xED; 
	  buffer1[2] = 0x00; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
      buffer1[1] = 0xEE; 
	  buffer1[2] = 0x06; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
      buffer1[1] = 0xED; 
	  buffer1[2] = 0x20; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      delay_ms(100); 		
      buffer1[1] = 0xED; 
	  buffer1[2] = 0x00; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
      buffer1[1] = 0xEE; 
	  buffer1[2] = 0x05; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
      buffer1[1] = 0xED; 
	  buffer1[2] = 0x08; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
	  delay_ms(100); 
      buffer1[1] = 0xED; 
	  buffer1[2] = 0x00; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
	  delay_ms(100); 
      buffer1[1] = 0xEE; 
	  buffer1[2] = 0x9F; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
      buffer1[1] = 0xED; 
	  buffer1[2] = 0x44; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
	  delay_ms(100);
      buffer1[1] = 0xED; 
	  buffer1[2] = 0x00; 
      SSD2828_W_Array(SigMode,channel,buffer1,0);
		/***read***/
	  SSD2828_W_Reg(SigMode,channel,0xB7,0x0200|0x0080);                               
      SSD2828_W_Reg(SigMode,channel,0xC1,0x0003); //return package size                                
      SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
      buffer1[0] = 0x01;
      buffer1[1] = 0xEC;                        
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      delay_ms(5);  
      SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
      SSD2828_W_Cmd(SigMode,channel,0xFF);
	  for(int i =0;i<1;i++)
		{
		SSD2828_W_Cmd(SigMode,channel,0xFA);		
        tmp=SPI3_Read_u16_Data(channel);
		buffer[3+i]=tmp>>8;
        buffer[4+i]=tmp;
        delay_ms(2);
		}
        buffer[0]=0x60;//往上返回	
		buffer[1]=0x20;
		buffer[2]=0x02;
		//SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);  
}

void VTDR7120_Erase_Flash(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	  u8 buffer1[4]; 
	  buffer1[0] = 0x02;
      buffer1[1] = 0xEE;
	  buffer1[2] = 0x60;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[1] = 0xED;
	  buffer1[2] = 0x20;
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
	  delay_ms(8000);   
      buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  //  buffer[4] = Uart_Error_None;
      //  STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写2810状态  ：ok
}

void VTDR7120_Flash_Statu(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  SSD2828_W_Reg(SigMode,channel,0xB7,0x0200);
	  u8 buffer1[6]; 
	  u16 tmp;
	  buffer1[0] = 0x02;
      buffer1[1] = 0x59;
	  buffer1[2] = 0x11;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x02;
      buffer1[1] = 0x6F;
	  buffer1[2] = 0x03;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x03;
      buffer1[1] = 0xF0;
	  buffer1[2] = 0xAA;
	  buffer1[3] = 0x10;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x02;
      buffer1[1] = 0xB8;
	  buffer1[2] = 0x04;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x03;
      buffer1[1] = 0xEA;
	  buffer1[2] = 0x30;
	  buffer1[3] = 0x20;
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
	  buffer1[0] = 0x01;
      buffer1[1] = 0x11;                    
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x02;
      buffer1[1] = 0xEE;
	  buffer1[2] = 0xAB;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[1] = 0xED;
	  buffer1[2] = 0x20;
      SSD2828_W_Array(SigMode,channel,buffer1,0);	
	  delay_ms(100);  
      buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[1] = 0xEE;
	  buffer1[2] = 0x06;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[1] = 0xED;
	  buffer1[2] = 0x20;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  delay_ms(100);  
      buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[1] = 0xEE;
	  buffer1[2] = 0x05;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[1] = 0xED;
	  buffer1[2] = 0x08;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  delay_ms(100);  
      buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  delay_ms(100);  
      buffer1[1] = 0xEE;
	  buffer1[2] = 0x01;
      SSD2828_W_Array(SigMode,channel,buffer1,0);  
      buffer1[1] = 0x65;
	  buffer1[2] = 0x07;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
      buffer1[0] = 0x03;
      buffer1[1] = 0xEE;
	  buffer1[2] = 0x02;
	  buffer1[3] = 0x02;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        delay_ms(100); 
        buffer1[0] = 0x02;
        buffer1[1] = 0xED;
        buffer1[2] = 0x10;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);  
        buffer1[1] = 0xED;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100); 
        buffer1[1] = 0xEE;
        buffer1[2] = 0x06;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[1] = 0xED;
        buffer1[2] = 0x20;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
        buffer1[1] = 0xED;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[1] = 0xEE;
        buffer1[2] = 0x05;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[1] = 0xED;
        buffer1[2] = 0x08;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
        buffer1[1] = 0xED;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
        buffer1[1] = 0xEE;
        buffer1[2] = 0x35;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[1] = 0xED;
        buffer1[2] = 0x08;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
        buffer1[1] = 0xED;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);	
		SSD2828_W_Reg(SigMode,channel,0xB7,0x0200|0x0080);                               
        SSD2828_W_Reg(SigMode,channel,0xC1,0x0003); //return package size                                
        //SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
        buffer1[0] = 0x01;
        buffer1[1] = 0xEF;                        
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        delay_ms(5);  
        SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
        SSD2828_W_Cmd(SigMode,channel,0xFF);
        for(int i =0;i<2;i++)
		{
			SSD2828_W_Cmd(SigMode,channel,0xFA);		
			tmp=SPI3_Read_u16_Data(channel);
			buffer[4+i]=tmp>>8;
			buffer[5+i]=tmp;
			delay_ms(5);
		}
 
		//  buffer[0]=0x60;	
		//	buffer[1]=0x22;
		//	buffer[4] = Uart_Error_None;
		//  SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		//	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		//  STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3); 
}

void VTDR7120_Check_Flash(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
        SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        u8 buffer1[5]; 
        u16 tmp;
        buffer1[0] = 0x02;
        buffer1[1] = 0x65;
        buffer1[2] = 0x04;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x04;
        buffer1[1] = 0xEE;
        buffer1[2] = 0x00;
        buffer1[3] = 0x00;
        buffer1[4] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x03;
        buffer1[1] = 0xEE;
        buffer1[2] = 0x0B;
        buffer1[3] = 0x08;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xED;
        buffer1[2] = 0x04;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
		buffer1[0] = 0x02;
        buffer1[1] = 0xED;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(50);
		
		/***********************************************
		buffer1[0] = 0x02;
        buffer1[1] = 0x65;
        buffer1[2] = 0x08;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
	
        buffer1[0] = 0x04;
        buffer1[1] = 0xEA;
        buffer1[2] = 0x1F;
        buffer1[3] = 0xCC;
        buffer1[4] = 0x3A;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
	
        buffer1[0] = 0x03;
        buffer1[1] = 0xFF;
        buffer1[2] = 0x5A;
        buffer1[3] = 0x80;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
	
        buffer1[0] = 0x02;
        buffer1[1] = 0xFA;
        buffer1[2] = 0x01;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		*****************************************************/
		
		
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);                               
        SSD2828_W_Reg(SigMode,channel,0xC1,0x0009); //return package size                                
        SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
        buffer1[0] = 0x01;
        buffer1[1] = 0xEC;                        
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        delay_ms(5);  
        SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
        SSD2828_W_Cmd(SigMode,channel,0xFF);
		for(i=0;i<8;i++)
        {
        SSD2828_W_Cmd(SigMode,channel,0xFA);		
        tmp=SPI3_Read_u16_Data(channel);
        buffer[4+i]=tmp>>8;
        buffer[5+i]=tmp;
        delay_ms(2);
        i++;
        }
        //下面需要恢复
        //  buffer[0]=0x60;	
        //	buffer[1]=0x23;
        //	buffer[2]=0x08;
        //	buffer[4] = Uart_Error_None;
        //  SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
        //  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        //  STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3); 	  
}

void VTDR7120_Step_Five(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
        SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        u8 buffer1[5]; 
        buffer1[0] = 0x02;
        buffer1[1] = 0x65;
        buffer1[2] = 0x08;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x04;
        buffer1[1] = 0xEA;
        buffer1[2] = 0x1F;
        buffer1[3] = 0xCC;
        buffer1[4] = 0x20;//此处应当为多少
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x03;
        buffer1[1] = 0xFF;
        buffer1[2] = 0x5A;
        buffer1[3] = 0x80;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFA;
        buffer1[2] = 0x01;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);  //回到高速
		delay_ms(5);
        //		buffer[4] = Uart_Error_None;
        //    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写2810状态  ：ok
}

void VTDR7120_OTP_Flash(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  u8 buffer1[6]; 	
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
      delay_ms(5);	
	  buffer1[0] = 0x05;
      buffer1[1] = 0xEE;
	  buffer1[2] = 0x32;
	  buffer1[3] = 0x00;
	  buffer1[4] = 0x01;
	  buffer1[5] = 0x00;
      SSD2828_W_Array(SigMode,channel,buffer1,0);
	  delay_ms(100);	 
	  buffer1[0] = 0x02;
      buffer1[1] = 0xED;
	  buffer1[2] = 0x02;
	  SSD2828_W_Array(SigMode,channel,buffer1,0);
	  delay_ms(9000);
      //delay_ms(60000);	
	  buffer1[0] = 0x02;
      buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
	  SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x03;
      buffer1[1] = 0xFF;
	  buffer1[2] = 0x5A;
	  buffer1[3] = 0x80;
	  SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x02;
      buffer1[1] = 0x01;
	  buffer1[2] = 0x00;
	  SSD2828_W_Array(SigMode,channel,buffer1,0);
	  delay_ms(100);
	  ////add  reset
	  //Set_2828_reset(OLED.SigMode);       //复位2828和OLED
	  SSD_RESET_LOW;		//复位SSD2828芯片
	  delay_ms(100);
	  SSD_RESET_HIGH;		
	  delay_ms(50); 			
		
        //	buffer[0]=0x60;	
        //	buffer[1]=0x25;
        //	buffer[2]=0x02;
        //	buffer[4] = Uart_Error_None;
        //  STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写2810状态  ：ok
}

//送Demura BMP数据到RAM
void VTDR7120_CRC_check(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[5]; 
        u16 tmp;
		delay_ms(5000);	
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        delay_ms(5);
        buffer1[0] = 0x03;
        buffer1[1] = 0xFF;
        buffer1[2] = 0x5A;
        buffer1[3] = 0x80;//Demura page0
        SSD2828_W_Array(SigMode,channel,buffer1,0);
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);                               
        SSD2828_W_Reg(SigMode,channel,0xC1,0x0009); //return package size                                
        SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
        buffer1[0] = 0x01;
        buffer1[1] = 0xfa;                        
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        delay_ms(5);  
        SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
        SSD2828_W_Cmd(SigMode,channel,0xFF);
        for(i=0;i<9;i++)
        {
        SSD2828_W_Cmd(SigMode,channel,0xFA);		
        tmp=SPI3_Read_u16_Data(channel);
        buffer[3+i]=tmp>>8;
        buffer[4+i]=tmp;
        delay_ms(2);
        i++;
        }
        //    buffer[0]=0x60;	
        //	  buffer[1]=0x26;
        //	  buffer[2]=0x09;
        //	//buffer[4] = Uart_Error_None;
        //    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        //    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3); 	  
}

void VTDR7120_Demura_on(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[5]; 
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        delay_ms(5);	
        buffer1[0] = 0x02;
        buffer1[1] = 0x59;
        buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
        SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		delay_ms(5);
        STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3); 	  	
}

void VTDR7120_Demura_off(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[5]; 
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
        delay_ms(5);	
        buffer1[0] = 0x02;
        buffer1[1] = 0x59;
        buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
        SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		delay_ms(5);
        STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3); 	  	
}










void ProcessForIc60( USBD_HandleTypeDef *pdev,uint8_t ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)//ADD BY PCS
{
  switch(buffer[1])
    {
    case 0x01://写寄存器
			VTDR7120_Write_Register(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;	
    case 0x02://读寄存器
			VTDR7120_Read_Register(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
    case 0x0D://OTP Gamma
			VTDR7120_Gamma_OTP_Start(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
    case 0x08://写Gamma数据    
			VTDR7120_Write_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
	case 0x09:                                      //读Gamma数据
			VTDR7120_Read_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break; 

    //===========Demura部分
    case 0x20:                                      //读Flash ID  
			VTDR7120_Read_Flash_ID(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
	case 0x21:                                      //擦除Demura数据    
			VTDR7120_Erase_Flash(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
	case 0x22:                                   
			VTDR7120_Flash_Statu(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
	case 0x23:
			VTDR7120_Check_Flash(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
	case 0x24:                                     
			VTDR7120_Step_Five(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
	case 0x25:
			VTDR7120_OTP_Flash(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
	case 0x26:
			VTDR7120_CRC_check(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
	case 0x27:
			VTDR7120_Demura_on(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
	case 0x28:
			VTDR7120_Demura_off(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
    default:	break;
    
    
    
    
    
    
    
    
    
    
    }
}